$(document).ready(function() {
    
    /* USER CONFIG TOGGLE MENU */
    $("#user").click(function () {
      $("#user-conf").slideToggle(200);
    });

    $("#user-conf").click(function () {
      $("#user-conf").fadeOut(200);
    });
    
    
    /* SHRINK SIDE-NAV */ 
    var menu_state = "open";
    
    $("#list-menu").click(function () {
        
      if(menu_state == "open") {
        menu_state = "closed";
        
        //shrink side-nav
        $("aside").css("width","60px");
        
        //shrink logo
        $(".tip-logo").hide();
        
        //move list-menu icon
    	$(this).css("left","60px");
        
        //change side-nav
        $(".main-nav span").css("display","none");
    	$(".main-nav").css("padding","13px 8px 15px 15px")
    	$(".nav-arrow").css("display","none");
        
        $(".submenu li").find("span").css("display","none");
        $(".submenu li").find("a").css("padding","12px 17px");
        
        $(".submenu li").find("a").attr("class","hint--right");
        $(".submenu li:first-child").find("a").attr("data-hint","Adicionar");
        $(".submenu li:last-child").find("a").attr("data-hint","Pesquisar");
        
        //shrink wrapper
    	$("div.wrapper").css("padding-left","60px");
      }
      
      else {   
        menu_state = "open";
        
        //expand side-nav
    	$("aside").css("width","240px");
        
        //expand logo
        $(".tip-logo").show();
        
        //move list-menu icon
    	$(this).css("left","240px");
        
        //change side-nav
    	$(".main-nav span").css("display","inline");
    	$(".main-nav").css("padding","7px 8px 9px 8px")
    	$(".nav-arrow").css("display","inline");
        
        $(".submenu li").find("span").css("display","inline");
        $(".submenu li").find("a").css("padding","8px 12px");
        
        $(".submenu li").find("a").removeAttr("class","hint--right");
        $(".submenu li:first-child").find("a").removeAttr("data-hint","Adicionar");
        $(".submenu li:last-child").find("a").removeAttr("data-hint","Pesquisar");
        
        //expand wrapper
    	$("div.wrapper").css("padding-left","260px");
      }
      
    }); //end shrink side-nav
    
    
    
    $(".side-nav li").click(function() {

      var state = $(this).attr("state");

      var id = $(this).next("div").attr("id");

      $(this).next("div").slideToggle();
      $(".submenu-box").not("#"+id).slideUp();

      if(state == "open") {
         $(this).attr("state","close");
         $(this).find(".nav-arrow").css("-webkit-transform",""); 
      }

      else {

        $("nav.side-nav ul li").attr("state","close");

        $(this).attr("state","open");

        $(this).find(".nav-arrow").css("-webkit-transform","rotate(90deg)");

        $("nav.side-nav ul li[state='close']").find(".nav-arrow").css("-webkit-transform","");

      }

      

    });

    //FILMES

    var ID = 0;
    $('div.img-movie').each(function() {
      ID++;
      $(this).attr('id', 'movie'+ID);
    });

    $(".conf-movie").click(function () {
      $(this).next("div").toggle(300);
    });
    
    $("#limpar_filme").click(function(){
      var limpar = confirm("Deseja limpar o formulário?");
      if (limpar)
        $("#novo_filme")[0].reset();
    });

});